#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <strings.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include "protobuf2.6/Person.pb.h"
using namespace std;

int main()
{
    int listenfd;
    if((listenfd = socket(PF_INET , SOCK_STREAM,0)) <0)
        exit(-1);

    struct sockaddr_in servaddr;
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(65533);
    servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");

    if(connect(listenfd , (struct sockaddr *)&servaddr , sizeof(servaddr)) < 0)
            exit(-1);


    netty::PersonMsg msg;
    string data;
    char sendbuf[1024]={0};
    msg.set_id(12);
    msg.set_name(" netty test");
    msg.set_age(45);


     msg.SerializeToString(&data);
     strcpy(sendbuf , data.c_str());
     printf(" data is %s " , sendbuf);
     size_t buffer_len = strlen(sendbuf);
     size_t b1 = htonl(buffer_len);
     write(listenfd, (const void*)&b1,4);
     if( send(listenfd,sendbuf,buffer_len ,0) <=0)
     {
         printf(" send error !");
     }


    close(listenfd);
    return 0;
}

